package com.e_manager.soft.emanager.controller;

import com.e_manager.soft.emanager.annotation.Authorization;
import com.e_manager.soft.emanager.annotation.BaseController;
import com.e_manager.soft.emanager.annotation.CurrentUser;
import com.e_manager.soft.emanager.entity.MstImage;
import com.e_manager.soft.emanager.entity.User;
import com.e_manager.soft.emanager.entity.parameter.MstImageParameter;
import com.e_manager.soft.emanager.resultMsg.ResultConstant;
import com.e_manager.soft.emanager.resultMsg.ResultInfo;
import com.e_manager.soft.emanager.service.MstImageService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;

/**
 * [MstImageController]<br>
 * 轮播图信息<br>
 * <br>
 * [功能概要]<br>
 * 轮播图信息<br>
 * <br>
 * [更新履历]<br>
 * 2018/03/15 ver1.00 JYS CORPORATION<br>
 *
 * @author JYS CORPORATION
 * @version 1.00
 */
@BaseController
@Authorization
public class MstImageController {
    @Autowired
    private MstImageService mstImageService;

    @ApiOperation(value = "获取轮播图列表", notes = "轮播图管理列表")
    @PostMapping(value = "/images", produces = {"application/json;charset=utf-8"})
    public ResultInfo<?> findAll(@RequestBody MstImageParameter mstImageParameter) {
        PageInfo<MstImage> pageInfo = null;
        ResultInfo resultInfo = new ResultInfo();
        try {
            //分页列表
            pageInfo = mstImageService.findAllByPage(mstImageParameter);
            //返回信息
            resultInfo.setMsg(ResultConstant.SUCCESS.getMessage());
            resultInfo.setData(pageInfo);
            resultInfo.setCode(ResultConstant.SUCCESS.getCode());
        } catch (Exception e) {
            resultInfo.setMsg(ResultConstant.FAIL.getMessage());
            resultInfo.setCode(ResultConstant.FAIL.getCode());
            e.printStackTrace();
        }
        return resultInfo;
    }

    @ApiOperation(value = "创建", notes = "根据轮播图对象创建")
    @PostMapping(value = "/image", produces = {"application/json;charset=utf-8"})
    public ResultInfo<?> save(@ApiParam(required = true, value = "需要参数:新增对象") @RequestBody MstImage mstImage, @CurrentUser User iuser) {
        //保存数据
        mstImage.setCreateUser(iuser.getUserID());
        ResultInfo info = mstImageService.save(mstImage);
        return info;
    }

    @ApiOperation(value = "修改信息", notes = "根据id来指定修改对象")
    @PutMapping(value = "/image", produces = {"application/json;charset=utf-8"})
    public ResultInfo<?> updateByid(@ApiParam(required = true, value = "需要参数:对象") @RequestBody MstImage mstImage, @CurrentUser User iuser) {
        //保存数据
        mstImage.setCreateUser(iuser.getUserID());
        ResultInfo info = mstImageService.save(mstImage);
        return info;
    }

    @ApiOperation(value = "修改状态信息", notes = "根据id来指定修改状态对象")
    @PatchMapping(value = "/image", produces = {"application/json;charset=utf-8"})
    public ResultInfo<?> updateByStatus(@ApiParam(required = true, value = "需要参数:对象") @RequestBody MstImage mstImage, @CurrentUser User iuser) {
        //保存数据
        mstImage.setCreateUser(iuser.getUserID());
        ResultInfo info = mstImageService.updateByStatus(mstImage);
        return info;
    }
}
